﻿/**************************************************************
*作者：Leon
*创建时间：2022/4/10 14:33:44
**************************************************************/
using System.Globalization;
using System.Windows.Data;

namespace Lad.DrawProject.Controls.Converters;

public class MmUnitConverter : IValueConverter
{
    public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
            return null;
        if(double.TryParse(value.ToString(), out var unit))
            return ConvertToDpi(unit);
        return value;
    }

    public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null)
            return null;
        if (double.TryParse(value.ToString(), out var unit))
            return ConvertToCm(unit);
        return value;
    }
    public static double ConvertToDpi(double value)
    {
        return DipHelper.MmToDip(value);
    }
    public static double ConvertToCm(double value)
    {
        return DipHelper.DipToMm(value);
    }
}
